home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-xfer-2.csn.net!yuma!steffend
- From: steffend@lamar.colostate.edu (Dave Steffen)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Performance: C vs. C++
- Followup-To: comp.lang.c++,comp.lang.c
- Date: 25 Jan 1996 18:55:19 GMT
- Organization: Colorado State University, Fort Collins, CO 80523
- Message-ID: <4e8jmn$2oo4@yuma.ACNS.ColoState.EDU>
- References: <30F6BAAC.12B5@iastate.edu> <31002F05.1B53@qm.claris.com>
- NNTP-Posting-Host: glitch.physics.colostate.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Steve Lee wrote:
-
- >I was wondering if anyone could tell me what the difference in
- > performance would be between writing a program in C++ vs. C. Assume
- > that the compilers are both of equal quality. I know that certain
- > features such as virtual functions and exception handling add
- > overhead. Are there any others? If you don't implement these
- > features that add the extra overhead, is C++ directly comparable to
- > C in performance then? The only other reason I could see C++ being
- > slower than C is programming style. Object-oriented is slower since
- > there are more layers, hence function call overhead.
-
-
- Raymond Fischer responded in part:
-
-
- > Hmmm. Two answers to that one. Both somewhat subjective.
-
- > First: A program that doesn't run doesn't run quickly. C++ can make
- > for fewer bugs in the resulting program and can allow you to produce
- > a working program quicker. In that sense C++ is faster.
-
- A very good point; my heavy numerical code is C++, with C++
- classes wrapping LAPACK calls. The improvement in readability has to
- be seen to be believed.
-
- > Second: C++ tends to be slower in execution - assuming that you use
- > C++ features. Virtual functions involve lookups, although you can
- > avoid that by not using virtual functions. The latest compilers (on
- > the Mac) provide zero-overhead exceptions. But where C++ tends to
- > cause the greatest problems with performance is in hidden function
- > calls. The most notorious of these is the call of the copy
- > constructor in parameters. Other sources are various type
- > conversions. C++ is slower not because it's an inherently slower
- > language, but because people tend to use it differently. With due
- > care there should be no significant performance hit.
-
- Exactly. With some care in writing my classes (and some minor
- tweaking) I'm getting performance out of G++ 2.7.0 that's within 5% of
- the original Fortran code - as compiled by a native
- compiler. Sometimes it's even faster.
-
- One of my advisor's colleagues has done some kind of _really_
- fancy LAPACK wrapper in C++. He says he's getting through-put that's
- significantly better than anything he's ever seen Fortran do. I'm
- still trying to figure out how he did it... ;-)
-
- Moral of the story: C++ can _FLY_... provided you know what
- you're doing. ;-)
-
- /\
- \/
-
- Dave Steffen No, his mind is not for rent
- Dept. of Physics To any God or Government
- Colorado State University Always hopeful, yet discontent
- steffend@lamar.colostate edu He knows changes aren't permanent-
- But change is...
- "Speak softly...
- ... and carry a black belt!" -Neal Peart / RUSH
- -----------------------------------------------------------------------
-